import axios, { type AxiosRequestConfig } from 'axios'

export const request = axios.create({
  responseType: 'blob',

})

request.interceptors.response.use(
  (response) => {
    if (response.status === 200 && response.data instanceof Blob) {
      return Promise.resolve(response)
    }
    return Promise.reject(new Error('interceptors 拦截器'))
  },
  (error) => {
    return Promise.reject(error)
  }
)


export function getBlob(url: string, config?: AxiosRequestConfig) {
    return request.get<Blob>(url, config)
}